]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
base-icon: Add an option to not show the label
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 20 Jan 2011 14:25:25 +0000 (15:25 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 9 Feb 2011 20:36:54 +0000 (21:36 +0100)
Currently there is a serious problem with ellipsization in various
parts of the overview. While wrapping the label or giving it more
space may be appropriate approaches for the application view, neither
works very well for the dash - possibly the best option there is to
not show the label at all.
So add a constructor parameter to BaseIcon to allow hiding the
label.

https://bugzilla.gnome.org/show_bug.cgi?id=636156

js/ui/iconGrid.js

index e8ac3aca16fdc59774abc4957208ebe4e6d75ae4..4bd6485dfb7a38553a465f4c3ec7129cbed27e29 100644 (file)
@@ -17,7 +17,8 @@ function BaseIcon(label, createIcon) {
 BaseIcon.prototype = {
     _init : function(label, params) {
         params = Params.parse(params, { createIcon: null,
-                                        setSizeManually: false });
+                                        setSizeManually: false,
+                                        showLabel: true });
         this.actor = new St.Bin({ style_class: 'overview-icon',
                                   x_fill: true,
                                   y_fill: true });
@@ -40,8 +41,12 @@ BaseIcon.prototype = {
 
         box.add_actor(this._iconBin);
 
-        this._name = new St.Label({ text: label });
-        box.add_actor(this._name);
+        if (params.showLabel) {
+            this._name = new St.Label({ text: label });
+            box.add_actor(this._name);
+        } else {
+            this._name = null;
+        }
 
         if (params.createIcon)
             this.createIcon = params.createIcon;
@@ -55,27 +60,35 @@ BaseIcon.prototype = {
         let availWidth = box.x2 - box.x1;
         let availHeight = box.y2 - box.y1;
 
-        let [labelMinHeight, labelNatHeight] = this._name.get_preferred_height(-1);
+        let iconSize = availHeight;
+
         let [iconMinHeight, iconNatHeight] = this._iconBin.get_preferred_height(-1);
-        let preferredHeight = labelNatHeight + this._spacing + iconNatHeight;
-        let labelHeight = availHeight >= preferredHeight ? labelNatHeight
-                                                         : labelMinHeight;
-        let iconSize = availHeight - this._spacing - labelHeight;
-        let iconPadding = (availWidth - iconSize) / 2;
+        let preferredHeight = iconNatHeight;
 
         let childBox = new Clutter.ActorBox();
 
+        if (this._name) {
+            let [labelMinHeight, labelNatHeight] = this._name.get_preferred_height(-1);
+            preferredHeight += this._spacing + labelNatHeight;
+
+            let labelHeight = availHeight >= preferredHeight ? labelNatHeight
+                                                             : labelMinHeight;
+            iconSize -= this._spacing + labelHeight;
+
+            childBox.x1 = 0;
+            childBox.x2 = availWidth;
+            childBox.y1 = iconSize + this._spacing;
+            childBox.y2 = childBox.y1 + labelHeight;
+            this._name.allocate(childBox, flags);
+        }
+
+        let iconPadding = (availWidth - iconSize) / 2;
+
         childBox.x1 = iconPadding;
         childBox.y1 = 0;
         childBox.x2 = availWidth - iconPadding;
         childBox.y2 = iconSize;
         this._iconBin.allocate(childBox, flags);
-
-        childBox.x1 = 0;
-        childBox.x2 = availWidth;
-        childBox.y1 = iconSize + this._spacing;
-        childBox.y2 = childBox.y1 + labelHeight;
-        this._name.allocate(childBox, flags);
     },
 
     _getPreferredWidth: function(actor, forHeight, alloc) {
@@ -84,9 +97,14 @@ BaseIcon.prototype = {
 
     _getPreferredHeight: function(actor, forWidth, alloc) {
         let [iconMinHeight, iconNatHeight] = this._iconBin.get_preferred_height(forWidth);
-        let [labelMinHeight, labelNatHeight] = this._name.get_preferred_height(forWidth);
-        alloc.min_size = iconMinHeight + this._spacing + labelMinHeight;
-        alloc.natural_size = iconNatHeight + this._spacing + labelNatHeight;
+        alloc.min_size = iconMinHeight;
+        alloc.natural_size = iconNatHeight;
+
+        if (this._name) {
+            let [labelMinHeight, labelNatHeight] = this._name.get_preferred_height(forWidth);
+            alloc.min_size += this._spacing + labelMinHeight;
+            alloc.natural_size += this._spacing + labelNatHeight;
+        }
     },
 
     // This can be overridden by a subclass, or by the createIcon